<?php
/**
 *  WB_ParameterListManager class unit tests
 *
 *  @author Jean-Lou Dupont
 *  @version @@package-version@@
 */

require_once 'PHPUnit/Framework.php';
require_once 'web-bloks/ParameterListManager/ParameterListManager.php';

class UnitTest extends PHPUnit_Framework_TestCase
{
	static $ref1 = array(
		'p1'		=> array( 'm' => true,  's' => false, 'l' => false, 'd' => null ),
		'p2'		=> array( 'm' => false, 's' => false, 'l' => false, 'd' => '' ),
		'p3'		=> array( 'm' => false, 's' => true,  'l' => true,  'd' => null, 'dq' => true, 'sq' => true ),
		// Restricted parameters
		'p4'		=> array( 'm' => false, 's' => true,  'l' => true,  'd' => null, 'r' => true  ),
		// Parameter with Type
		'p5'		=> array( 'm' => false, 's' => true,  'l' => true,  'd' => null, 't' => 'number'
							),			
	);
	static $i1 = array(
		'p1'	=> 'p1_value',
		'p2'	=> 'p2_value',
		'p3'	=> 'p3_value',
		'p4'	=> 'p4_value',
		);

	// for mandatory parameters testing
	static $i2 = array(
		//'p1'	=> 'p1_value',  // missing one mandatory parameter
		'p2'	=> 'p2_value',
		'p3'	=> 'p3_value',
		'p4'	=> 'p4_value',
		);

	// for invalid parameters testing
	static $i3 = array(
		'p1'	=> 'p1_value',
		'p2'	=> 'p2_value',
		'p3'	=> 'p3_value',
		'p4'	=> 'p4_value',
		
		'p_inv'	=> 'p_inv_value', // invalid
		);

	// for type errors testing
	static $i4 = array(
		'p1'	=> 'p1_value',
		'p2'	=> 'p2_value',
		'p3'	=> 'p3_value',
		'p4'	=> 'p4_value',
		'p5'	=> 'p5_value', // must be a number
		);
	
	/**
	 * Destroys the singleton before each test.
	 */
	public function setup()
	{
		
	}
	public function testConstructor()
	{
		$ps = array( 'list' => self::$i1, 'ref' => self::$ref1 );
		$m = new WB_ParameterListManager( $ps );
		
        $this->assertEquals( true, is_object( $m ) );
	}

	public function testEverythingNormal()
	{
		$ps = array( 'list' => self::$i1, 'ref' => self::$ref1 );
		$m = new WB_ParameterListManager( $ps );
		
		#var_dump( $m->whatError() );
		
        $this->assertEquals( false, $m->isError() );
	}
	
	public function testMandatoryParameters()
	{
		$ps = array( 'list' => self::$i2, 'ref' => self::$ref1 );
		$m = new WB_ParameterListManager( $ps );
		
        $this->assertEquals( true, $m->isError() );
        $this->assertEquals( true, $m->foundMissing() );		
        $this->assertEquals( false, $m->foundInvalid() );		
        $this->assertEquals( false, $m->foundTypeErrors() );				
	}

	public function testInvalidParameters()
	{
		$ps = array( 'list' => self::$i3, 'ref' => self::$ref1 );
		$m = new WB_ParameterListManager( $ps );
		
        $this->assertEquals( true, $m->isError() );
        $this->assertEquals( false, $m->foundMissing() );				
        $this->assertEquals( true, $m->foundInvalid() );		
        $this->assertEquals( false, $m->foundTypeErrors() );				
	}

	public function testTypeErrorsParameters()
	{
		$ps = array( 'list' => self::$i4, 'ref' => self::$ref1 );
		$m = new WB_ParameterListManager( $ps );
		
		#var_dump( $m->getTypeErrorsList() );
		
        $this->assertEquals( true, $m->isError() );
        $this->assertEquals( false, $m->foundMissing() );						
        $this->assertEquals( false, $m->foundInvalid() );
        $this->assertEquals( true, $m->foundTypeErrors() );		
	}

/*	
	public function test1()
	{
		$result = true;
		try
		{

		}
		catch( Exception $e )
		{
			$result = false;			
		}
		
        $this->assertEquals( $result, true );		
	}
*/
} // end class